<?php 
namespace Admin\Controller;
use \Think\Controller;


class AttributeController extends Controller{

		protected $attrModel = null ;

		public function __construct()
		{
				parent::__construct();
				$this->attrModel = D('attribute');
		}

		public function attribute_list()
		{
			$where = array();

			if(isset($_GET['type_id']))
			{
				$where ['php22_attribute.type_id']= array('eq',I('get.type_id'));
			}
			

			$count      = $this->attrModel->join('php22_goods_type on php22_attribute.type_id = php22_goods_type.type_id','INNER')->where($where)->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$Page->setConfig('next','下一页');
			$Page->setConfig('prev','上一页');
			$Page->setConfig('end','最后一页');
			$show       = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $this->attrModel->limit($Page->firstRow.','.$Page->listRows)->where($where)->select();
			$types = D('goods_type')->getType();

			$this->assign('list',$list);// 赋值数据集
			$this->assign('page',$show);// 赋值分页输出
			$this->assign('types',$types);
			$this->display();
		}
		public function attribute_add()
		{
			if(IS_POST)
			{		

				if($this->attrModel->create(I('post.')))
				{
					if($this->attrModel->add())
					{
						$this->success('商品属性添加成功');
						exit;
					}
					else
					{
						$this->error('商品属性添加失败');
						exit;
					}
				}
				else
				{
					$this->error($this->attrModel->getError());
					exit;
				}
			}


			$types = D('goods_type')->getType();

			$this->assign('types',$types);
			$this->display();
		}
		public function attribute_edit()
		{

			$types = D('goods_type')->getType();

			$this->assign('types',$types);
			$this->display();
		}

		public function attribute_delete()
		{
			//$info = $this->attrModel->delete(I('get.attr_id'));

			if($info)
			{
				$str = '删除成功';
				$this->ajaxReturn($str,'json');
			}
			else
			{
				$str = '删除失败';
				$this->ajaxReturn($str,'json');				
			}
		}
}



 ?>